<?php declare(strict_types=1);
namespace Umserv\ExchangeInterfaces\V1\Core\Http;

/**
 * Класс обертка для модели ответа c ошибкой
 */
final class ErrorResponse extends \Umserv\ExchangeInterfaces\V1\Core\Http\BaseResponse
{
    public function getAsJson(): string {
        $code = 400;

        if(is_int($this->code)){
            $code = $this->code;
        }else{
            $code = $this->code->value;
        }

        return json_encode([
            'response' => [],
            'error' => [
                'code' => $code,
                'message' => $this->message ?? ''
            ]
        ],JSON_UNESCAPED_SLASHES | JSON_HEX_QUOT);
    }
}